package com.dapeis.core.utils.json;

import java.lang.reflect.Type;

import net.sf.json.util.NewBeanInstanceStrategy;

import com.ag.core.exception.InvalidParamException;
import com.ag.utils.json.AGsonBuilder;
import com.dapeis.core.utils.DBConfigUtils;
import com.dapeis.core.utils.StylistConstants;
import com.dapeis.domain.Collocation;
import com.dapeis.domain.ext.CollocationExt;
import com.dapeis.im.tim.TIMUtil;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;

/**
 * @author 作者 E-mail: hzyuanyong@126.com
 * @version 创建时间：2017年5月15日 上午10:56:34 类说明
 */
public class ColloncationExtGsonAdapter implements
	JsonSerializer<CollocationExt> {

    @Override
    public JsonElement serialize(CollocationExt src, Type typeOfSrc,
	    JsonSerializationContext context) {
	JsonObject json = new JsonObject();
	json.addProperty("id", src.getId());
	json.addProperty("timId",TIMUtil.getDPSUserIdentifier(src.getId()));
	json.addProperty("headImg",
		StylistConstants.PASERIMGPATH(src.getHeadImg()));
	json.addProperty("nickName", src.getNickName());
	json.addProperty("qrCode",
		StylistConstants.PASERIMGPATH(src.getQrCodeUrl()));
	json.addProperty("backgroundImg",
		StylistConstants.PASERIMGPATH(src.getBackgroundImg()));
	json.addProperty("state", src.getState());
	json.addProperty("auditState", src.getAuditState());
	json.addProperty("honor", src.getHonor());
	json.addProperty("goodsStyle", src.getGoodStyle());
	json.addProperty("remark", src.getRemark());
	json.addProperty("serverCity", DBConfigUtils.getCity(null == src
		.getCollocationInformation() ? new String() : src
		.getCollocationInformation().getServerCity()));
	json.addProperty("cityCode",
		null == src.getCollocationInformation() ? new String() : src
			.getCollocationInformation().getServerCity());
	
	json.addProperty("age", DBConfigUtils.getAgeByBirthday(null == src
		.getCollocationInformation() ? 0 : src
		.getCollocationInformation().getBirthday()));
	json.addProperty("sex", null == src.getCollocationInformation() ? 1
		: src.getCollocationInformation().getSex());
	return json;
    }
}
